package com.bytedance.ttnet.a;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.location.Address;
import android.net.Uri;
import android.os.Build;
import android.os.Looper;
import android.os.Message;
import android.util.Pair;

import com.bytedance.common.a.f;
import com.bytedance.common.utility.collection.WeakHandler;
import com.bytedance.frameworks.baselib.network.connectionclass.ConnectionClassManager;
import com.bytedance.frameworks.baselib.network.connectionclass.ConnectionQuality;
import com.bytedance.frameworks.baselib.network.connectionclass.ConnectionClassManager.b;
import com.bytedance.frameworks.baselib.network.http.BaseRequestContext;
import com.bytedance.frameworks.baselib.network.http.b.a.OkHttp3Builder;
import com.bytedance.frameworks.baselib.network.http.cronet.a.SsCronetHttpClient;
import com.bytedance.frameworks.baselib.network.http.util.HttpQueryHelper;
import com.bytedance.frameworks.baselib.network.http.util.ProcessUtils;
import com.bytedance.ttnet.b.GetDomainContext;
import com.bytedance.ttnet.b.RequestParams;
import com.bytedance.ttnet.hostmonitor.HostMonitor;
import com.bytedance.ttnet.hostmonitor.HostMonitorBR;
import com.bytedance.ttnet.hostmonitor.Logger;
import com.bytedance.ttnet.hostmonitor.e;
import com.bytedance.ttnet.hostmonitor.h;
import com.google.gson.GsonBuilder;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.net.InetAddress;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import inline.UrlDemo;

public class AppConfig implements
        WeakHandler.Callback,
        b,
        SsCronetHttpClient.a$b,
        com.bytedance.frameworks.baselib.network.http.AppConfig.b,
        com.bytedance.frameworks.baselib.network.http.AppConfig.RxBytesSampleController,
        com.bytedance.frameworks.core.encrypt.a,
        com.bytedance.ttnet.aa.b {
    static boolean b;
    static boolean g;
    private static int P;
    private static int Q;
    private static int R;
    private static int S;
    private static int T;
    private static int U;
    private static int Z;
    private static AppConfig instance;
    private static int i;
    private static int j;
    private static int z;

    static {
        String[] v0 = new String[]{"dm.toutiao.com", "dm.bytedance.com", "dm.pstatp.com"};
        i = 0;
        j = 0;
        z = 3;
        P = 1;
        Q = 1;
        R = 1;
        S = 1;
        b = false;
        T = -1;
        U = -1;
        Z = -1;
        g = false;
    }

    public final Context mContext;
    final WeakHandler mWeakHandler = new WeakHandler(Looper.getMainLooper(), ((WeakHandler.Callback) this));
    private final boolean k;
    public NetChannelSelect mNetChannelSelect;
    e e;
    com.bytedance.ttnet.hostmonitor.b f;
    private String A = "";
    private int B = 0;
    private int C = 0;
    private int D = 0;
    private int E = 0;
    private int F = 0;
    private int G = 1;
    private int H = 1;
    private int I = 0;
    private int J = 1;
    private int K = 1;
    private int L = 1;
    private int M = 1;
    private int N = 1;
    private int O = 0;
    private volatile int V;
    private volatile boolean W;
    private f X = null;
    private HostMonitorBR Y = new HostMonitorBroadcastReceiver(this);
    private volatile boolean l = false;
    private boolean m = true;
    private boolean n = false;
    private long o = 0;
    private long p = 0;
    private volatile boolean q = false;
    private HashMap<String, String> r = new HashMap();
    private HashMap<String, String> s = new HashMap();
    private HashMap<String, String> mReverseMap = new HashMap();
    private HashMap<String, InetAddress[]> u;
    private Map<HttpsFilter, HttpsFilter> v;
    private HashMap<HttpsFilter, HttpsFilter> w;
    private HashMap<String, String> x = new HashMap();
    private HashMap<String, String> y = new HashMap();

    private AppConfig(Context context, boolean arg10) {
        Class v4_1;
        e v7;
        Context v3_1;
        HostMonitorBR v0_3;
        int v1 = 1;
        int v2 = 0;
        this.mContext = context;
        String v0 = android.support.design.a.I(android.support.design.a.y());
        this.mReverseMap.put(v0, "i");
        this.mReverseMap.put(android.support.design.a.I("security"), "si");
        this.mReverseMap.put(android.support.design.a.I("isub"), "isub");
        this.mReverseMap.put(android.support.design.a.I("ichannel"), "ichannel");
        this.mReverseMap.put(android.support.design.a.I("log"), "log");
        this.mReverseMap.put(android.support.design.a.I("mon"), "mon");
        this.k = arg10;
        if (this.k) {
            try {
                this.f = new com.bytedance.ttnet.hostmonitor.b(v0);
                e v0_2 = new e(this.mContext);
                v0_2.e = 1800000;
                com.bytedance.ttnet.hostmonitor.b v3 = this.f;
                if (v3 != null && !v0_2.b().keySet().contains(v3)) {
                    v0_2.b.put(v3, new h());
                }

                this.e = v0_2;
                v0_3 = this.Y;
                v3_1 = this.mContext;
                IntentFilter v4 = new IntentFilter();
                v4.addAction(new e(v3_1).c());
                v3_1.registerReceiver(v0_3, v4);
                v7 = this.e;
                Logger.a("HostMonitor", "saving configuration");
                SharedPreferences.Editor v0_4 = v7.a().edit();
                if (v7.b != null && !v7.b.isEmpty()) {
                    GsonBuilder v3_2 = new GsonBuilder();
                    v3_2.serializeNulls();
                    v0_4.putString("hosts", v3_2.create().toJson(v7.b));
                }

                if (v7.c != null && !v7.c.isEmpty()) {
                    v0_4.putString("broadcastAction", v7.c);
                }

                if (v7.d > 0) {
                    v0_4.putInt("socketTimeout", v7.d);
                }

                if (v7.e >= 0) {
                    v0_4.putInt("checkInterval", v7.e);
                }

                if (v7.f > 0) {
                    v0_4.putInt("maxAttempts", v7.f);
                }

                v0_4.apply();
                if (!v7.b().isEmpty()) {
                    v2 = 1;
                }

                v3_1 = v7.a;
                v4_1 = com.bytedance.ttnet.hostmonitor.a.class;
                if (v2 == 0) {
                    v1 = 2;
                }
                String v5 = "TtnetUtil";
                StringBuilder v6 = new StringBuilder();
                v0 = v2 != 0 ? "enabling" : "disabling";
                Logger.a(v5, v6.append(v0).append(" connectivity receiver").toString());
                v3_1.getPackageManager().setComponentEnabledSetting(new ComponentName(v3_1, v4_1), v1, 1);
                Object v0_5 = v7.a.getSystemService(Context.ALARM_SERVICE);
                PendingIntent v6_1 = PendingIntent.getBroadcast(v7.a, 0, HostMonitor.a(v7.a), 0);
                Logger.a("HostMonitor", "cancelling scheduled checks");
                ((AlarmManager) v0_5).cancel(v6_1);
                if (v2 == 0) {
                    return;
                }

                if (v7.d() > 0) {
                    Logger.a("HostMonitor", "scheduling periodic checks every " + v7.d() / 1000 + " seconds");
                    ((AlarmManager) v0_5).setRepeating(1, System.currentTimeMillis() + (((long) v7.d())), ((long) v7.d()), v6_1);
                }

                Logger.a("HostMonitor", "triggering reachability check");
                mNetChannelSelect.b(v7.a);
            } catch (Throwable v0_1) {
                v0_1.printStackTrace();
            }
        }
    }

    public static synchronized AppConfig getInstance(Context context) {
        if (instance == null) {
            boolean v0_1 = ProcessUtils.b(context);
            instance = new AppConfig(context.getApplicationContext(), v0_1);
            if (v0_1) {
                UrlDemo.a = instance;
                SsCronetHttpClient.a(instance);
                com.bytedance.ttnet.aa.a(instance);
                ConnectionClassManager v0_2 = ConnectionClassManager.Holder.sInstance;
                AppConfig v2 = instance;
                if (v2 != null) {
                    v0_2.b.add(v2);
                }

                v0_2.a.get();
                com.bytedance.frameworks.baselib.network.http.AppConfig.a((com.bytedance.frameworks.baselib.network.http.AppConfig.RxBytesSampleController) instance);
            } else {
                UrlDemo.a = new i();
                j v0_3 = new j();
                SsCronetHttpClient.a(((SsCronetHttpClient.a$b) v0_3));
                com.bytedance.ttnet.aa.a(((com.bytedance.ttnet.aa.b) v0_3));
            }

            com.bytedance.frameworks.baselib.network.http.AppConfig.a((com.bytedance.frameworks.baselib.network.http.AppConfig.RxBytesSampleController) instance);
            com.bytedance.ttnet.a.f.a(context);
        }
        return instance;
    }

    static Context a(AppConfig arg1) {
        return arg1.mContext;
    }

    static String a(Map arg6) {
        String v0_2;
        try {
            JSONArray v1 = new JSONArray();
            if (arg6 != null && arg6.size() > 0) {
                Iterator v2 = arg6.keySet().iterator();
                while (v2.hasNext()) {
                    Object v0_1 = v2.next();
                    JSONObject v3 = new JSONObject();
                    v3.put(HttpsFilter.a, ((HttpsFilter) v0_1).urlRegex);
                    v3.put(HttpsFilter.b, ((HttpsFilter) v0_1).errCount);
                    v1.put(v3);
                }
            }

            v0_2 = v1.toString();
        } catch (Throwable v0) {
            v0_2 = "";
        }

        return v0_2;
    }

    private static void parseUrlReplaceMap(HashMap arg5, JSONArray arg6) {
        int v0_1;
        if (arg6 == null) {
            return;
        }

        try {
            int v1 = arg6.length();
            v0_1 = 0;
            while (true) {
                label_4:
                if (v0_1 >= v1) {
                    return;
                }
                JSONObject v2 = arg6.optJSONObject(v0_1);
                String v3 = v2.optString("origin");
                if (!android.support.design.a.isTextEmpty(v3)) {
                    String v2_1 = v2.optString("target");
                    if (!android.support.design.a.isTextEmpty(v2_1)) {
                        arg5.put(v3, v2_1);
                    }
                }
                ++v0_1;
                continue;
            }
        } catch (Exception v0) {
            com.bytedance.common.utility.Logger.w("AppConfig", "parseUrlReplaceMap exception: " + v0);
        }
    }

    private static boolean checkSign(String arg4, GetDomainContext arg5) {
        boolean v0_1;
        String v0 = arg5.rawSign;
        if (android.support.design.a.isTextEmpty(v0)) {
            v0_1 = false;
            return v0_1;
        }

        String v1 = com.bytedance.common.utility.aa.md5("ByteDance" + com.bytedance.common.utility.aa.md5(arg4));
        if (!android.support.design.a.isTextEmpty(v1) && v1.length() == 32) {
            arg5.localSign = v1;
            try {
                arg5.ssSign = android.support.design.a.decode(v0);
            } catch (Throwable v0_2) {
                StringWriter v2 = new StringWriter();
                v0_2.printStackTrace(new PrintWriter(((Writer) v2)));
                arg5.errMsg = v2.toString();
            }

            v0_1 = v1.equals(arg5.ssSign);
        } else {
            arg5.errMsg = "generate local sign error.";
            v0_1 = true;
        }

        return v0_1;
    }

    private static boolean a(HashMap arg6, JSONObject arg7) throws JSONException {
        boolean v0_1;
        Matcher v2 = Pattern.compile("^([0-9a-zA-Z-]{1,40}\\.){1,5}[0-9a-zA-Z]{1,20}$").matcher("");
        Iterator v3 = arg7.keys();
        while (true) {
            if (v3.hasNext()) {
                Object v0 = v3.next();
                String v4 = arg7.getString(((String) v0));
                if (android.support.design.a.isTextEmpty(((String) v0))) {
                    v0_1 = false;
                } else if (!v2.reset(((CharSequence) v4)).matches()) {
                    v0_1 = false;
                } else {
                    arg6.put(v0, v4);
                    continue;
                }
            } else {
                return true;
            }

            return v0_1;
        }
    }

    static NetChannelSelect b(AppConfig arg1) {
        return arg1.mNetChannelSelect;
    }

    private static void parseDnsMap(HashMap arg10, JSONArray arg11) {
        int v2;
        ArrayList v4;
        if (arg11 != null) {
            try {
                int v3 = arg11.length();
                v4 = new ArrayList();
                v2 = 0;
                while (true) {
                    if (v2 >= v3) {
                        return;
                    }
                    ((List) v4).clear();
                    JSONObject v0_1 = arg11.optJSONObject(v2);
                    String v5 = v0_1.getString("host");
                    if (!android.support.design.a.isTextEmpty(v5)) {
                        JSONArray v6 = v0_1.optJSONArray("ip");
                        int v7 = Math.min(v6.length(), 3);
                        int v0_2;
                        for (v0_2 = 0; v0_2 < v7; ++v0_2) {
                            String v8 = v6.getString(v0_2);
                            if (com.bytedance.frameworks.baselib.network.http.util.e.a(v8)) {
                                InetAddress v8_1 = InetAddress.getByAddress(v5, InetAddress.getByName(v8).getAddress());
                                if (v8_1 != null) {
                                    ((List) v4).add(v8_1);
                                }
                            }
                        }
                        if (((List) v4).size() <= 0) {
                        } else {
                            InetAddress[] v0_3 = new InetAddress[((List) v4).size()];
                            ((List) v4).toArray(((Object[]) v0_3));
                            arg10.put(v5, v0_3);
                        }
                    }

                    ++v2;
                    continue;
                }
            } catch (Exception v0) {
                com.bytedance.common.utility.Logger.w("AppConfig", "parseDnsMap exception: " + v0);
            }
        }
        return;
    }

    static void c(AppConfig arg0) {
        arg0.q();
    }

    static Map d(AppConfig arg1) {
        return arg1.v;
    }

    public static boolean httpRetry() {
        boolean v0 = Q > 0 ? true : false;
        return v0;
    }

    public static boolean https2http() {
        boolean v0 = P > 0 ? true : false;
        return v0;
    }

    public static boolean showHijack() {
        boolean v0 = R > 0 ? true : false;
        return v0;
    }

    public static boolean i() {
        boolean v0 = S > 0 ? true : false;
        return v0;
    }

    public static int o() {
        return z;
    }

    private static String[] p() {
        return com.bytedance.ttnet.cc.a().d();
    }

    public final boolean isHttpUrlMatch(String arg5, HttpsFilter[] arg6, boolean arg7) {
        Object v0_3;
        boolean v0;
        if (android.support.design.a.isTextEmpty(arg5)) {
            v0 = false;
        } else {
            Map v0_1 = this.v;
            if (arg7) {
                v0_1 = this.w;
            }
            if (v0_1 != null && v0_1.size() > 0) {
                Iterator v3 = v0_1.keySet().iterator();
                do {
                    if (v3.hasNext()) {
                        v0_3 = v3.next();
                        boolean v2 = (android.support.design.a.isTextEmpty(arg5)) || ((HttpsFilter) v0_3).d == null ? false : ((HttpsFilter) v0_3).d.reset(((CharSequence) arg5)).matches();
                        if (!v2) {
                            continue;
                        }

                        break;
                    }
                    return false;
                }
                while (true);

                arg6[0] = ((HttpsFilter) v0_3);
                return true;
            }
            v0 = false;
        }

        return v0;
    }

    private String tryFilterHttps(URI arg9, BaseRequestContext arg10, String alterScheme, boolean arg12) {
        String url = null;
        int v2 = 0;
        if (arg9 != null) {
            if (!(arg10 instanceof RequestParams)) {
                arg10 = null;
            }

            if (arg10 != null && (((RequestParams) arg10).force_no_https)) {
                return arg9.toString();
            }

            int v0_1 = this.B > 0 ? 1 : 0;
            if (v0_1 != 0 && (b)) {
                url = arg9.toString();
                try {
                    if (!android.support.design.a.a(this.mContext)) {
                        if (com.bytedance.common.utility.Logger.debug()) {
                            com.bytedance.common.utility.Logger.w("AppConfig", "filterUrl origin url = " + url);
                        }

                        int v3 = this.G > 0 ? 1 : 0;
                        if (v3 != 0 && !android.support.design.a.isTextEmpty(alterScheme)) {
                            url = android.support.design.a.a(arg9, new com.bytedance.frameworks.baselib.network.http.util.c(arg9.getHost(), arg9.getPort(), alterScheme)).toString();
                            if (arg10 != null && (alterScheme.equals("https"))) {
                                ((RequestParams) arg10).using_https = true;
                            }

                            if (!com.bytedance.common.utility.Logger.debug()) {
                                return url;
                            }

                            com.bytedance.common.utility.Logger.w("AppConfig", "filterUrl replace alterScheme = " + alterScheme + " url = " + url);
                            return url;
                        }

                        HttpsFilter[] v3_1 = new HttpsFilter[1];
                        if (!this.isHttpUrlMatch(url, v3_1, arg12)) {
                            return url;
                        }

                        HttpsFilter v4 = v3_1[0];
                        if (v4 != null) {
                            boolean isHostChangeEnable = v4.errCount <= z ? true : false;
                            if (com.bytedance.common.utility.Logger.debug()) {
                                com.bytedance.common.utility.Logger.w("AppConfig", "isHostChangeEnable = " + isHostChangeEnable
                                        + " urlRegex = " + v4.urlRegex + " errCount = " + v4.errCount);
                            }

                            if (!isHostChangeEnable) {
                            } else {
                                v2 = 1;
                            }
                        }
                        if (arg10 != null) {
                            int v1_1 = v4 == null ? -1 : v4.errCount;
                            ((RequestParams) arg10).https_fail_times = v1_1;
                        }

                        if (!url.startsWith("http")) {
                            return url;
                        }

                        if (v2 != 0 && ((android.support.design.a.isTextEmpty(alterScheme)) || !"http".equals(alterScheme))) {
                            url = url.replaceFirst("http", "https");
                            if (arg10 == null) {

                            } else {
                                ((RequestParams) arg10).using_https = true;
                            }
                        }

                        if (!com.bytedance.common.utility.Logger.debug()) {
                            return url;
                        }

                        com.bytedance.common.utility.Logger.w("AppConfig", "filterUrl replace url = " + url);
                        return url;
                    } else {
                    }

                    return url;
                } catch (Throwable v1) {
                    return url;
                }
            }
            url = arg9.toString();
        }

        return url;
    }

    private URI a(URI arg7, boolean arg8) {
        URI v0_5;
        String v0_4;
        Object v2_1;
        Object v1_1;
        HashMap v1;
        HashMap v0_1;
        if (this.H > 0 && arg7 != null) {
            try {
                v0_1 = this.x;
                if (arg8) {
                    v1 = this.y;
                } else {
                    v1 = v0_1;
                }
                if (v1 == null) {
                    return arg7;
                }

                if (((Map) v1).isEmpty()) {
                    return arg7;
                }

                StringBuilder v0_2 = new StringBuilder();
                String v2 = arg7.getHost();
                int v3 = arg7.getPort();
                String v4 = arg7.getRawPath();
                if (v2 != null) {
                    v0_2.append(v2);
                    if (v3 > 0) {
                        v0_2.append(':');
                        v0_2.append(v3);
                    }
                }

                if (v4 == null || !v4.startsWith("/")) {
                    v0_2.append('/');
                }

                if (v4 != null) {
                    v0_2.append(v4);
                }

                String v3_1 = v0_2.toString();
                if (com.bytedance.common.utility.Logger.debug()) {
                    com.bytedance.common.utility.Logger.d("AppConfig", "tryReplaceUrl originUrlPrefix = " + v3_1);
                }

                v0_4 = (String) ((Map) v1).get(v3_1);
                if (android.support.design.a.isTextEmpty((String) v0_4)) {
                    Iterator v4_1 = ((Map) v1).entrySet().iterator();
                    do {
                        if (v4_1.hasNext()) {
                            v1_1 = v4_1.next();
                            if (v1_1 == null) {
                                continue;
                            }

                            v2_1 = ((Map.Entry) v1_1).getKey();
                            v1_1 = ((Map.Entry) v1_1).getValue();
                            if (!v3_1.startsWith(((String) v2_1))) {
                                continue;
                            }
                            v0_4 = v3_1.replaceFirst(((String) v2_1), ((String) v1_1));
                        }
                        break;
                    } while (true);

                }

                if (android.support.design.a.isTextEmpty(v0_4)) {
                    return arg7;
                }

                StringBuilder v1_2 = new StringBuilder();
                if (arg7.getScheme() != null) {
                    v1_2.append(arg7.getScheme());
                    v1_2.append("://");
                }

                v1_2.append(v0_4);
                URI v3_2 = new URI(v1_2.toString());
                v0_5 = android.support.design.a.a(v3_2.getScheme(), v3_2.getHost(), v3_2.getPort(), v3_2.getRawPath(), arg7.getRawQuery(), arg7.getRawFragment());
                if (com.bytedance.common.utility.Logger.debug()) {
                    com.bytedance.common.utility.Logger.d("AppConfig", "tryReplaceUrl resultUri = " + v0_5.toString());
                }
            } catch (Throwable v0) {
                v0.printStackTrace();
                return arg7;
            }

            arg7 = v0_5;
        }

        return arg7;
    }

    private void a(Map arg7, JSONArray arg8, boolean arg9) {
        Iterator v1_1;
        HttpsFilter v2_1;
        int v0 = 0;
        if (arg8 != null) {
            try {
                if (com.bytedance.common.utility.Logger.debug()) {
                    com.bytedance.common.utility.Logger.w("AppConfig", "parseDnsMap fromLocal = " + arg9 + " data = " + arg8.toString());
                }
                int v1 = arg8.length();
                while (true) {
                    if (v0 >= v1) {
                        synchronized (this) {
                            if (this.v != null && this.v.size() > 0) {
                                v1_1 = this.v.keySet().iterator();
                                while (v1_1.hasNext()) {
                                    Object v0_2 = v1_1.next();
                                    if (!arg7.containsKey(v0_2)) {
                                        continue;
                                    }
                                    arg7.remove(v0_2);
                                    arg7.put(v0_2, v0_2);
                                }
                            }
                            return;
                        }
                    }

                    try {
                        v2_1 = new HttpsFilter();
                        if (arg9) {
                            JSONObject v3 = arg8.optJSONObject(v0);
                            v2_1.a(v3.optString(HttpsFilter.a));
                            int v3_1 = v3.optInt(HttpsFilter.b);
                            if (this.O > 0) {
                                if (com.bytedance.common.utility.Logger.debug()) {
                                    com.bytedance.common.utility.Logger.w("AppConfig", "addHttpsUrlErrCount Need Load");
                                }
                                v2_1.errCount = v3_1;
                            } else {
                                if (com.bytedance.common.utility.Logger.debug()) {
                                    com.bytedance.common.utility.Logger.w("AppConfig", "addHttpsUrlErrCount No Need Load");
                                }
                                v2_1.errCount = 0;
                            }
                        } else {
                            v2_1.a(arg8.optString(v0));
                            v2_1.errCount = 0;
                        }
                        arg7.put(v2_1, v2_1);
                    } catch (Exception v2) {

                    }
                    ++v0;
                    continue;
                }
            } catch (Throwable v0_1) {
                com.bytedance.common.utility.Logger.w("AppConfig", "parseHttpsFilter exception: " + v0_1);
            }
        }
        return;
    }

    public final String a(String arg11, BaseRequestContext arg12) {
        URI v0_3;
        Pair v4_1;
        Object v2_1;
        Object v0_2;
        String v6;
        int v5;
        String v4;
        URI v3;
        Object v1 = null;
        int v0 = 0;
        if (!android.support.design.a.isTextEmpty(arg11)) {
            try {
                v3 = this.a(URI.create(arg11), false);
                v4 = v3.getHost();
                v5 = v3.getPort();
                v6 = v3.getScheme();
                String[] v2 = p();
                int v7 = v2.length;
                while (v0 < v7) {
                    if (v2[v0].equals(v4)) {
                        return arg11;
                    }

                    ++v0;
                }

                if (this.k) {
                    this.k();
                } else {
                    this.j();
                }

                synchronized (this) {
                    v0_2 = this.mReverseMap.get(v4);
                    if (v0_2 == null) {
                        v2_1 = v1;
                    } else if (this.r != null) {
                        v2_1 = this.r.get(v0_2);
                    } else {
                        v2_1 = v1;
                    }

                    if ((android.support.design.a.I(android.support.design.a.y()).equals(v4)) || (android.support.design.a.I(android.support.design.a.y()).equals(v2_1))) {
                        if (this.mNetChannelSelect != null) {
                            v4_1 = this.mNetChannelSelect.a();
                            if (v4_1 != null) {
                                v0_2 = v4_1.first;
                                v1 = v4_1.second;
                            } else {
                                v0_2 = v1;
                                v1 = v2_1;
                            }
                        } else {
                            v0_2 = v1;
                            v1 = v2_1;
                        }
                    } else if (v2_1 == null) {
                        v0_2 = v1;
                        v1 = v2_1;
                    } else {
                        v0_2 = v1;
                        v1 = v2_1;
                    }
                    v2_1 = v0_2;
                }
                try {
                    if (!android.support.design.a.isTextEmpty(((String) v1))) {
                        v0_3 = android.support.design.a.a(v3, new com.bytedance.frameworks.baselib.network.http.util.c(((String) v1), v5, v6));
                    } else {
                        v0_3 = v3;
                    }
                    return this.tryFilterHttps(v0_3, arg12, ((String) v2_1), false);
                } catch (Throwable v0_1) {
                    v0_1.printStackTrace();
                }
            } catch (Throwable v0_1) {
            }
        }

        return arg11;
    }

    public final List a(String arg3) {
        InetAddress[] v1;
        List v0 = null;
        if (!android.support.design.a.isTextEmpty(arg3) && (this.k)) {
            this.k();
            synchronized (this) {
                if (this.u != null) {
                    v1 = this.u.get(arg3);
                } else {
                    v1 = null;
                }
                if (v1 != null && v1.length > 0) {
                    ArrayList v0_2 = new ArrayList();
                    ((List) v0_2).addAll(Arrays.asList(((Object[]) v1)));
                    if (Z != 0) {
                        Collections.shuffle(((List) v0_2));
                    }
                    return v0;
                } else {
                    return this.e(arg3);
                }
            }
        }

        return v0;
    }

    public final void a(int arg2) {
        if (this.V != arg2) {
            this.V = arg2;
        }
    }

    public final void a(ConnectionQuality arg4) {
        if ((com.bytedance.common.utility.Logger.debug()) && arg4 != null) {
            com.bytedance.common.utility.Logger.d("AppConfig", "onBandwidthStateChange bandwidthState = " + arg4);
        }
    }

    public final void a(boolean arg7) {
        long v2 = 0;
        if (this.k) {
            if (!this.n) {
                if (this.m) {
                    this.m = false;
                    this.o = v2;
                    this.p = v2;
                }

                long v0 = arg7 ? 10800000 : 43200000;
                v2 = System.currentTimeMillis();
                if (v2 - this.o <= v0) {
                } else {
                    if (v2 - this.p <= 120000) {
                    } else {
                        boolean v0_1 = android.support.design.a.isNetworkAvailable(this.mContext);
                        if ((this.q) && !v0_1) {
                        } else {
                            this.n = true;
                            if (v0_1) {
                                this.p = System.currentTimeMillis();
                            }
                            new com.bytedance.ttnet.a.d(this, "AppConfigThread", v0_1).start();
                        }
                    }
                }
            }
            if (this.mNetChannelSelect == null) {
                return;
            }

            this.mNetChannelSelect.b(this.mContext);
            return;
        }

        if (this.o <= v2) {
            try {
                new com.bytedance.ttnet.a.c(this, "LoadDomainConfig4Other-Thread").start();
            } catch (Throwable v0_2) {
            }
        }
    }

    public final boolean a() {
        boolean v0 = this.D > 0 ? true : false;
        return v0;
    }

    final boolean a(JSONArray arg42, boolean arg43) throws JSONException {
        com.bytedance.ttnet.a.f v4_8;
        int v36;
        int v35;
        int v34;
        int v33;
        int v32;
        int v31_1;
        HashMap v31;
        String v7_3;
        HashMap v4_7;
        LinkedHashMap v7_2;
        int v5_4;
        int v4_6;
        int v30;
        int v29;
        int v28;
        int v27;
        int v26;
        int v25;
        int v24;
        int v23;
        int v22;
        int v21;
        int v20;
        int v19;
        int v18;
        int v17;
        int v16;
        int v15;
        int v14;
        String v8_2;
        JSONArray v5_3;
        String v13 = null;
        int v9;
        HashMap v7_1;
        JSONObject v5_2;
        JSONObject v12;
        JSONObject v4_5;
        boolean v4_4;
        long v8;
        String v4_3;
        HttpQueryHelper v7;
        Throwable v4_1;
        GetDomainContext v3_1 = null;
        String v2 = arg43 ? "https://" : "http://";
        GetDomainContext v4 = null;
        String[] v10 = p();
        int v11 = v10.length;
        int v6 = 0;
        while (v6 < v11) {
            String v5 = v10[v6];
            try {
                v3_1 = new GetDomainContext();
                v3_1.useHttps = arg43;
                StringBuilder v4_2 = new StringBuilder();
                v4_2.append(v2).append(v5).append("/get_domains/v4/");
                Address v5_1 = com.bytedance.ttnet.cc.a().a(this.mContext);
                v7 = new HttpQueryHelper(v4_2.toString());
                if (v5_1 != null && (v5_1.hasLatitude()) && (v5_1.hasLongitude())) {
                    v7.put("latitude", v5_1.getLatitude());
                    v7.put("longitude", v5_1.getLongitude());
                    v4_3 = v5_1.getLocality();
                    if (!android.support.design.a.isTextEmpty(v4_3)) {
                        v7.put("city", Uri.encode(v4_3));
                    }
                }
                v4_3 = Build.VERSION.SDK_INT < 21 ? Build.CPU_ABI : Build.SUPPORTED_ABIS[0];
                v7.put("abi", v4_3);
                v4_3 = v7.toString();
                v3_1.url = v4_3;
                v8 = System.currentTimeMillis();
                v5 = android.support.design.a.a(v4_3, v3_1);
                v3_1.queryTime = System.currentTimeMillis() - v8;
                if (!arg43) {
                    v4_4 = checkSign(v5, v3_1);
                } else {
                    v4_4 = arg43;
                }
                arg42.put(v3_1.toJson());
                if (!v4_4) {
                    ++v6;
                    v4 = v3_1;
                    continue;
                } else if (android.support.design.a.isTextEmpty(v5)) {
                    ++v6;
                    v4 = v3_1;
                    continue;
                }
                v4_5 = new JSONObject(v5);
                if (!"success".equals(v4_5.getString("message"))) {
                    ++v6;
                    v4 = v3_1;
                    continue;
                }

                v12 = v4_5.getJSONObject("data");
                v4_5 = v12.optJSONObject("mapping");
                if (v4_5 == null) {
                    v5_2 = new JSONObject();
                } else {
                    v5_2 = v4_5;
                }
                v7_1 = new HashMap();
                if (a(v7_1, v5_2)) {
                    synchronized (this) {
                        this.r = v7_1;
                        HashMap v8_1 = new HashMap();
                        v8_1.putAll(((Map) v7_1));
                        this.s = v8_1;
                    }
                    v9 = 1;
                } else {
                    v9 = 0;
                }
                v13 = v5_2.toString();
                v5_3 = v12.optJSONArray("dns_mapping");
                v7_1 = new HashMap();
                parseDnsMap(v7_1, v5_3);
                v4_3 = "";
                if (v5_3 == null) {
                    v8_2 = v4_3;
                } else if (v7_1.size() > 0) {
                    v8_2 = v5_3.toString();
                } else {
                    v8_2 = v4_3;
                }
                Z = v12.optInt("shuffle_dns");
                com.bytedance.frameworks.baselib.network.http.AppConfig.a(v12.optInt("use_dns_mapping", -1));
                T = v12.optInt("use_http_dns", -1);
                U = v12.optInt("collect_recent_page_info_enable", -1);
                synchronized (this) {
                    this.u = v7_1;
                }
                v14 = v12.optInt("https_dns_err_max", 3);
                v15 = v12.optInt("https_dns_err_policy", 0);
                v16 = v12.optInt("hs_open", 0);
                v17 = v12.optInt("ok_http_open", 0);
                v18 = v12.optInt("ok_http3_open", 0);
                v19 = v12.optInt("chromium_open", 0);
                v20 = v12.optInt("http_dns_enabled", 0);
                v21 = v12.optInt("detect_open", 0);
                v22 = v12.optInt("detect_native_page", 1);
                v23 = v12.optInt("collect_recent_page_info_enable", 1);
                v24 = v12.optInt("i_host_select_open", 0);
                v25 = v12.optInt("i_host_select_open_v2", 1);
                v26 = v12.optInt("replace_url_open", 1);
                v27 = v12.optInt("add_ss_queries_open", 0);
                v28 = v12.optInt("add_ss_queries_header_open", 1);
                v29 = v12.optInt("add_ss_queries_plaintext_open", 1);
                v30 = v12.optInt("image_ttnet_enabled", 1);
                v4_6 = v12.optInt("sample_band_width_enabled", 1);
                v5_4 = v12.optInt("dynamic_timeout_enabled", 1);
                i = v12.optInt("send_api_exception_sample", 1);
                j = v12.optInt("send_ss_etag_sample", 1);
                synchronized (this) {
                    z = v14;
                    this.O = v15;
                    this.B = v16;
                    this.C = v19;
                    this.D = v20;
                    this.E = v21;
                    this.F = v24;
                    this.G = v25;
                    this.H = v26;
                    this.I = v27;
                    this.J = v28;
                    this.K = v29;
                    this.L = v30;
                    this.M = v4_6;
                    this.N = v5_4;
                }
                v4_4 = this.N > 0 ? true : false;
                com.bytedance.frameworks.baselib.network.http.AppConfig.a(v4_4);
                this.mNetChannelSelect = this.m() ? NetChannelSelect.a(this.mContext) : null;
                if (this.mNetChannelSelect != null) {
                    this.mNetChannelSelect.a(this.mContext, v12);
                }
                v4_3 = "";
                try {
                    v5_3 = v12.optJSONArray("https_dns");
                    v7_2 = new LinkedHashMap();
                    this.a(v7_2, v5_3, false);
                    v5 = a(v7_2);
                    synchronized (this) {
                        this.v = ((Map) v7_2);
                        v4_7 = new HashMap();
                        v4_7.putAll(((Map) v7_2));
                        this.w = v4_7;
                    }
                    v7_3 = v5;
                } catch (Exception e) {
                    v7_3 = v4_3;
                }
                v4_3 = "";
                try {
                    v5_3 = v12.optJSONArray("url_replace_mapping");
                    v31 = new HashMap();
                    parseUrlReplaceMap(v31, v5_3);
                    if (v5_3 == null) {
                        v5 = v4_3;
                    } else if (v31.size() > 0) {
                        v4_3 = v5_3.toString();
                        v5 = v4_3;
                    } else {
                        v5 = v4_3;
                    }

                    synchronized (this) {
                        this.x = v31;
                        v4_7 = new HashMap();
                        v4_7.putAll(v31);
                        this.y = v4_7;
                    }
                } catch (Throwable v41) {
                    v5 = v4_3;
                }

                v31_1 = v12.optInt("https_to_http", 1);
                v32 = v12.optInt("http_to_https", 1);
                v33 = v12.optInt("https_retry_http", 1);
                v34 = v12.optInt("http_show_hijack", 1);
                v35 = v12.optInt("http_verify_sign", 1);
                synchronized (this) {
                    P = v31_1;
                    Q = v33;
                    R = v34;
                    S = v35;
                }
                if (v12.optInt("enable_req_ticket", 1) > 0) {
                    v4_4 = true;
                } else {
                    v4_4 = false;
                }
                com.bytedance.ttnet.utils.a.a(v4_4);
                v4_3 = v12.optString("frontier_urls", "");
                v36 = v12.optInt("disable_framed_transport", 0);
                this.V = v12.optInt("disable_encrypt_switch", 0);
                if (this.V == 2) {
                    synchronized (this) {
                        SharedPreferences.Editor v37 = this.mContext.getSharedPreferences("app_log_encrypt_switch_count", 0).edit();
                        v37.putInt("app_log_encrypt_faild_count", 0);
                        v37.apply();
                    }
                }
                if (v36 <= 0) {

                } else {
                    OkHttp3Builder.a(v36);
                }
                synchronized (this) {
                    SharedPreferences.Editor v36_2 = this.mContext.getSharedPreferences("ss_app_config", 0).edit();
                    if (v9 != 0) {
                        v36_2.putString("config_mapping", v13);
                    }

                    v36_2.putString("static_dns_mapping", v8_2);
                    v36_2.putString("https_dns", v7_3);
                    v36_2.putString("url_replace_mapping", v5);
                    v36_2.putInt("https_dns_err_max", v14);
                    v36_2.putInt("https_dns_err_policy", v15);
                    v36_2.putInt("hs_open", v16);
                    v36_2.putInt("ok_http_open", v17);
                    v36_2.putInt("ok_http3_open", v18);
                    v36_2.putInt("chromium_open", v19);
                    v36_2.putInt("http_dns_enabled", v20);
                    v36_2.putInt("detect_open", v21);
                    v36_2.putInt("detect_native_page", v22);
                    v36_2.putInt("collect_recent_page_info_enable", v23);
                    v36_2.putInt("i_host_select_open", v24);
                    if (this.mNetChannelSelect != null) {
                        this.mNetChannelSelect.a(v36_2);
                    }

                    v36_2.putInt("i_host_select_open_v2", v25);
                    v36_2.putInt("replace_url_open", v26);
                    v36_2.putInt("add_ss_queries_open", v27);
                    v36_2.putInt("add_ss_queries_header_open", v28);
                    v36_2.putInt("add_ss_queries_plaintext_open", v29);
                    v36_2.putInt("image_ttnet_enabled", v30);
                    v36_2.putInt("send_api_exception_sample", i);
                    v36_2.putInt("send_ss_etag_sample", j);
                    v36_2.putInt("shuffle_dns", Z);
                    v36_2.putInt("use_http_dns", T);
                    v36_2.putInt("use_http_dns_refetch_on_expire", U);
                    v36_2.putLong("last_refresh_time", System.currentTimeMillis());
                    v36_2.putInt("https_to_http", v31_1);
                    v36_2.putInt("http_to_https", v32);
                    v36_2.putInt("https_retry_http", v33);
                    v36_2.putInt("http_show_hijack", v34);
                    v36_2.putInt("http_verify_sign", v35);
                    v36_2.putString("frontier_urls", v4_3);
                    v36_2.putInt("android_log_encrypt_switch", this.V);
                    v36_2.putInt("image_ttnet_enabled", this.L);
                    v36_2.putInt("sample_band_width_enabled", this.M);
                    v36_2.putInt("dynamic_timeout_enabled", this.N);
                    v36_2.commit();
                    try {
                        LinkedHashMap v5_6 = new LinkedHashMap();
                        if (!android.support.design.a.isTextEmpty(v4_3) && !v4_3.equals(this.A)) {
                            this.A = v4_3;
                            ((Map) v5_6).put("frontier_urls", v4_3);
                        }

                        ((Map) v5_6).put("chromium_open", Integer.valueOf(v19));
                        ((Map) v5_6).put("http_dns_enabled", Integer.valueOf(v20));
                        ((Map) v5_6).put("add_ss_queries_open", Integer.valueOf(v27));
                        ((Map) v5_6).put("add_ss_queries_header_open", Integer.valueOf(v28));
                        ((Map) v5_6).put("add_ss_queries_plaintext_open", Integer.valueOf(v29));
                        com.bytedance.ttnet.cc.a().a(this.mContext, ((Map) v5_6));
                    } catch (Throwable v41) {
                        v41.printStackTrace();
                    }
                }
                if (com.bytedance.ttnet.a.f.a() == null) {
                    android.support.design.a.a(this.mContext, 2, v13);
                    return false;
                }

                v4_8 = com.bytedance.ttnet.a.f.a();
                if (v12 == null) {
                    android.support.design.a.a(this.mContext, 2, v13);
                    return false;
                }

                if (v12.length() <= 0) {
                    android.support.design.a.a(this.mContext, 2, v13);
                    return false;
                }

                v5_4 = v12.optInt("image_opt_switch", 0);
                v8 = v12.optLong("image_opt_black_interval", 0);
                int v7_4 = v12.optInt("image_opt_failed_times", 0);
                int v12_1 = v12.optInt("image_opt_limit_count", 0);
                SharedPreferences.Editor v14_1 = v4_8.b().edit();
                if (v5_4 != v4_8.a) {
                    v14_1.putInt("image_opt_switch", v5_4);
                }

                if (v8 != v4_8.b) {
                    v14_1.putLong("image_opt_black_interval", v8);
                }

                if (v7_4 != v4_8.c) {
                    v14_1.putInt("image_opt_failed_times", v7_4);
                }

                if (v12_1 != v4_8.d) {
                    v14_1.putInt("image_opt_limit_count", v12_1);
                }

                v14_1.apply();
                v4_8.a = v5_4;
                v4_8.b = v8;
                v4_8.c = v7_4;
                v4_8.d = v12_1;
                android.support.design.a.a(this.mContext, 2, v13);
                return false;
            } catch (Throwable v41) {
                v41.printStackTrace();
                if (v3_1 != null) {
                    StringWriter v5_7 = new StringWriter();
                    v41.printStackTrace(new PrintWriter(v5_7));
                    v3_1.errMsg = v5_7.toString();
                    arg42.put(v3_1.toJson());
                }
                com.bytedance.common.utility.Logger.w("AppConfig", "try app config exception: " + v41);
                ++v6;
                v4 = v3_1;
            }

        }
        return false;
    }

    public final boolean b() {
        boolean v0 = this.I > 0 ? true : false;
        return v0;
    }

    public final boolean shouldSampleNet(String requestUrl) {
        boolean v0 = false;
        if (!android.support.design.a.isTextEmpty(requestUrl) && this.M > 0) {
            try {
                String host = URI.create(requestUrl).getHost();
                if (android.support.design.a.isTextEmpty(host)) {
                    return v0;
                }

                if (!host.endsWith(android.support.design.a.z())) {
                    return v0;
                }
            } catch (Throwable v1) {
                v1.printStackTrace();
                return v0;
            }

            v0 = true;
        }

        return v0;
    }

    public final String c(String arg11) {
        URI v0_3;
        Object v1_2 = null;
        Pair v4_2;
        Object v2_1 = null;
        Object v0_2;
        String v6 = null;
        int v5 = 0;
        URI uri = null;
        Pair v1 = null;
        if (!android.support.design.a.isTextEmpty(arg11)) {
            try {
                uri = this.a(URI.create(arg11), true);
                String host = uri.getHost();
                v5 = uri.getPort();
                v6 = uri.getScheme();
                String[] v2 = p();
                int v7 = v2.length;
                int v0_1;
                for (v0_1 = 0; v0_1 < v7; ++v0_1) {
                    if (v2[v0_1].equals(host)) {
                        return arg11;
                    }
                }

                v0_2 = this.mReverseMap.get(host);
                if (v0_2 == null) {
                    v2_1 = v1;
                } else if (this.s != null) {
                    v2_1 = this.s.get(v0_2);
                } else {
                    v2_1 = v1;
                }
                if ((android.support.design.a.I(android.support.design.a.y()).equals(host))
                        || (android.support.design.a.I(android.support.design.a.y()).equals(v2_1))) {
                    if (this.mNetChannelSelect != null) {
                        if (mNetChannelSelect.mUiSelectedNetChannel != null) {
                            if (com.bytedance.common.utility.Logger.debug()) {
                                com.bytedance.common.utility.Logger.d("NetChannelSelect", "getSelectPair mUiSelectedNetChannel = " + mNetChannelSelect.mUiSelectedNetChannel.toString());
                            }
                            v4_2 = new Pair(mNetChannelSelect.mUiSelectedNetChannel.j, mNetChannelSelect.mUiSelectedNetChannel.a);
                        } else {
                            v4_2 = v1;
                        }
                        if (v4_2 == null) {
                            v0_2 = v1;
                            v1_2 = v2_1;
                        } else {
                            v0_2 = v4_2.first;
                            v1_2 = v4_2.second;
                        }
                    } else {
                        v0_2 = v1;
                        v1_2 = v2_1;
                    }
                } else if (v2_1 == null) {
                    v0_2 = v1;
                    v1_2 = v2_1;
                } else {
                    v0_2 = v1;
                    v1_2 = v2_1;
                }

                v2_1 = v0_2;
            } catch (Throwable v0) {
                v0.printStackTrace();
                Object v9_1 = v2_1;
                v2_1 = v1_2;
                v1_2 = v9_1;
            }
            try {
                if (!android.support.design.a.isTextEmpty(((String) v1_2))) {
                    v0_3 = android.support.design.a.a(uri, new com.bytedance.frameworks.baselib.network.http.util.c(((String) v1_2), v5, v6));
                } else {
                    v0_3 = uri;
                }
                arg11 = this.tryFilterHttps(v0_3, null, ((String) v2_1), true);
            } catch (Throwable v0) {
                v0.printStackTrace();
            }
        }

        return arg11;
    }

    public final boolean c() {
        boolean v0 = this.J > 0 ? true : false;
        return v0;
    }

    private void d(String arg5) {
        if (!android.support.design.a.isTextEmpty(arg5)) {
            try {
                JSONObject v0_1 = new JSONObject(arg5);
                HashMap v1 = new HashMap();
                if (!a(v1, v0_1)) {
                    return;
                }

                this.r = v1;
                HashMap v0_2 = new HashMap();
                v0_2.putAll(((Map) v1));
                this.s = v0_2;
            } catch (Exception v0) {
                com.bytedance.common.utility.Logger.w("AppConfig", "load local config exception: " + v0);
            }
        }
    }

    public final boolean d() {
        boolean v0 = this.K > 0 ? true : false;
        return v0;
    }

    private List e(String arg6) {
        boolean v1_1;
        String v3;
        Context v2;
        List v0 = null;
        f v1_2;
        try {
            if (T > 0 || (com.bytedance.common.utility.Logger.debug())) {
                synchronized (this) {
                    if (this.X == null) {
                        v2 = this.mContext;
                        v3 = "131950";
                        v1_1 = U > 0 ? true : false;
                        this.X = com.bytedance.common.a.e.a(v2, v3, v1_1);
                        this.X.c();
                        if (com.bytedance.common.utility.Logger.debug()) {
                            this.X.b();
                        }
                    }
                    v1_2 = this.X;
                }
            } else {
                v1_2 = ((f) v0);
            }

            if (v1_2 != null) {
                if (!arg6.endsWith(android.support.design.a.z()) && !arg6.endsWith(".pstatp.com") && !arg6.endsWith(".bytecdn.com")) {
                    return v0;
                }

                List v1_3 = v1_2.a(arg6);
                if (v1_3 != null && v1_3.size() > 0) {
                    if (com.bytedance.common.utility.Logger.debug()) {
                        com.bytedance.common.utility.Logger.d("AppConfig", "httpdns: " + arg6 + " " + v1_3);
                    }

                    return v1_3;
                }

                if (!com.bytedance.common.utility.Logger.debug()) {
                    return v0;
                }

                com.bytedance.common.utility.Logger.d("AppConfig", "httpdns: " + arg6 + " no result");
            }
            return v0;
        } catch (Exception e) {

        }
        return v0;
    }

    public final boolean e() {
        boolean v0 = true;
        if (!com.bytedance.common.utility.Logger.debug() && this.C <= 0) {
            v0 = false;
        }

        return v0;
    }

    public void handleMsg(Message message) {
        switch (message.what) {
            case 101: {
                this.n = false;
                this.o = System.currentTimeMillis();
                if (this.m) {
                    this.a(false);
                }

                try {
                    this.q();
                    if (T > 0) {
                        return;
                    }

                    if (this.X == null) {
                        return;
                    }

                    this.X.d();
                } catch (Throwable v0) {
                    v0.printStackTrace();
                }

                return;
            }
            case 102: {
                this.n = false;
                if (this.m) {
                    this.a(false);
                }
                return;
            }
        }

        return;


    }

    final void j() {
        synchronized (this) {
            if (System.currentTimeMillis() - this.o <= 3600000) {
                return;
            }

            this.o = System.currentTimeMillis();
            try {
                this.d(android.support.design.a.a(this.mContext, 2));
            } catch (Exception v0_1) {
            }
        }
    }

    final synchronized void k() {
        LinkedHashMap v0_7;
        HashMap v1_1;
        HashMap v0_5;
        boolean v0_4;
        Class v1;
        String v0_3;
        String v8;
        Context v7;
        NetChannelSelect v6;
        String v3;
        String v2_1;
        long v0_1;
        long v2;
        String v5;
        SharedPreferences v4;
        synchronized (this) {
            try {
                if (this.q) {
                    return;
                }
                this.q = true;
                v4 = this.mContext.getSharedPreferences("ss_app_config", 0);
                v5 = v4.getString("config_mapping", null);
                v2 = v4.getLong("last_refresh_time", 0);
                v0_1 = System.currentTimeMillis();
                if (v2 <= v0_1) {
                    v0_1 = v2;
                }
                this.o = v0_1;
                this.d(v5);
                v2_1 = v4.getString("static_dns_mapping", null);
                v3 = v4.getString("https_dns", null);
                v5 = v4.getString("url_replace_mapping", null);
                z = v4.getInt("https_dns_err_max", 3);
                this.O = v4.getInt("https_dns_err_policy", 0);
                this.B = v4.getInt("hs_open", 0);
                v4.getInt("ok_http_open", 0);
                v4.getInt("ok_http3_open", 0);
                this.C = v4.getInt("chromium_open", 0);
                this.D = v4.getInt("http_dns_enabled", 0);
                this.E = v4.getInt("detect_open", 0);
                v4.getInt("detect_native_page", 1);
                v4.getInt("collect_recent_page_info_enable", 1);
                this.F = v4.getInt("i_host_select_open", 0);
                if (this.m()) {
                    this.mNetChannelSelect = NetChannelSelect.a(this.mContext);
                } else {
                    NetChannelSelect v0_2 = null;
                    this.mNetChannelSelect = v0_2;
                }
                v6 = NetChannelSelect.a(this.mContext);
                v7 = this.mContext;
                if (v4 == null) {

                } else {

                    try {
                        v8 = v4.getString("i_host_select", null);
                        v6.a = v4.getInt("i_host_select_interval", 1800);
                        v6.b = v4.getInt("i_host_select_interval_http_timeout", 60);
                        v6.c = v4.getInt("i_host_max_fail", 2);
                        v6.d = v4.getLong("i_host_last_select_time", 0);
                        v0_1 = v4.getLong("i_host_atomic_long", -1);
                        v6.i = v4.getString("i_host_last_bssid", null);
                        v6.j = v4.getInt("i_host_last_net_type", -1);
                        if (v0_1 >= 9223372036854775807L) {
                            v0_1 = -1;
                        }

                        if (v6.h != null) {
                            v6.h.getAndSet(v0_1);
                        }

                        if (!android.support.design.a.isTextEmpty(v8)) {
                            label_251:
                            v6.a(v7, new JSONObject(v8));
                            v0_3 = v4.getString("i_host_select_netchannel_host", "");
                            if (!android.support.design.a.isTextEmpty(v0_3)) {
                                v1 = NetChannelSelect.class;
                                synchronized (v1) {
                                    v6.a((NetChannelSelect.g$a) v6.e.get(v0_3));
                                }
                            }

                            if (!getInstance(v7).m()) {
                            } else {
                                if (com.bytedance.common.utility.Logger.debug()) {
                                    com.bytedance.common.utility.Logger.d("NetChannelSelect", "select from init");
                                }
                                v6.a(v7, "onInit");
                            }
                        }
                    } catch (Throwable v0) {

                    }
                }
                this.G = v4.getInt("i_host_select_open_v2", 1);
                this.H = v4.getInt("replace_url_open", 1);
                this.I = v4.getInt("add_ss_queries_open", 0);
                this.J = v4.getInt("add_ss_queries_header_open", 1);
                this.K = v4.getInt("add_ss_queries_plaintext_open", 1);
                this.L = v4.getInt("image_ttnet_enabled", 1);
                this.M = v4.getInt("sample_band_width_enabled", 1);
                this.N = v4.getInt("dynamic_timeout_enabled", 1);
                if (this.N > 0) {
                    v0_4 = true;
                } else {
                    v0_4 = false;
                }
                com.bytedance.frameworks.baselib.network.http.AppConfig.a(v0_4);
                i = v4.getInt("send_api_exception_sample", 1);
                j = v4.getInt("send_ss_etag_sample", 1);
                Z = v4.getInt("shuffle_dns", -1);
                com.bytedance.frameworks.baselib.network.http.AppConfig.a(v4.getInt("use_dns_mapping", -1));
                T = v4.getInt("use_http_dns", -1);
                U = v4.getInt("use_http_dns_refetch_on_expire", -1);
                v0_5 = new HashMap();
                if (android.support.design.a.isTextEmpty(v2_1)) {

                } else {
                    parseDnsMap(v0_5, new JSONArray(v2_1));
                    synchronized (this) {
                        this.u = v0_5;
                    }
                }
                v0_5 = new HashMap();
                if (android.support.design.a.isTextEmpty(v5)) {

                } else {
                    parseUrlReplaceMap(v0_5, new JSONArray(v5));
                    synchronized (this) {
                        this.x = v0_5;
                        v1_1 = new HashMap();
                        v1_1.putAll(((Map) v0_5));
                        this.y = v1_1;
                    }
                }
                v0_7 = new LinkedHashMap();
                if (android.support.design.a.isTextEmpty(v3)) {
                } else {
                    this.a(v0_7, new JSONArray(v3), true);
                    synchronized (this) {
                        this.v = ((Map) v0_7);
                        v1_1 = new HashMap();
                        v1_1.putAll(((Map) v0_7));
                        this.w = v1_1;
                    }
                }
                P = v4.getInt("https_to_http", 1);
                v4.getInt("http_to_https", 1);
                Q = v4.getInt("https_retry_http", 1);
                R = v4.getInt("http_show_hijack", 1);
                S = v4.getInt("http_verify_sign", 1);
                b = v4.getBoolean("https_available", false);
                this.A = v4.getString("frontier_urls", "");
            } catch (Throwable v0) {
            }
        }
    }

    public final boolean l() {
        boolean v0 = this.E > 0 ? true : false;
        return v0;
    }

    public final boolean m() {
        boolean v0 = this.F > 0 ? true : false;
        return v0;
    }

    public final boolean n() {
        boolean v0 = true;
        if (!this.W) {
            Class v2 = AppConfig.class;
            synchronized (v2) {
                this.V = this.mContext.getSharedPreferences("ss_app_config", 0).getInt("android_log_encrypt_switch", 0);
                this.W = true;
            }
        }
        if (this.V != 0) {
            v0 = false;
        }
        return v0;
    }

    private void q() {
        Object v0_1;
        Iterator<Map.Entry<String, String>> v1;
        try {
            if (T > 0 && !com.bytedance.ttnet.aa.a()) {
                if (this.mReverseMap != null) {
                    v1 = this.mReverseMap.entrySet().iterator();
                    while (v1.hasNext()) {
                        v0_1 = v1.next();
                        if (v0_1 == null) {
                            continue;
                        }

                        this.e((String) ((Map.Entry) v0_1).getKey());
                    }
                }

                if (this.mNetChannelSelect == null) {
                    return;
                }

                Map v0_2 = this.mNetChannelSelect.e;
                if (v0_2 == null) {
                    return;
                }

                v1 = v0_2.entrySet().iterator();
                while (v1.hasNext()) {
                    v0_1 = v1.next();
                    if (v0_1 == null) {
                        continue;
                    }

                    this.e((String) ((Map.Entry) v0_1).getKey());
                }
            }

            return;
        } catch (Throwable v0) {
            v0.printStackTrace();
            return;
        }
    }

    public static final class HttpsFilter {
        static String a;
        static String b;

        static {
            HttpsFilter.a = "url_regex";
            HttpsFilter.b = "err_count";
        }

        public String urlRegex;
        public int errCount;
        Matcher d;

        HttpsFilter() {

        }

        final void a(String arg3) {
            if (!android.support.design.a.isTextEmpty(arg3)) {
                this.urlRegex = arg3;
                this.d = Pattern.compile(arg3).matcher("");
            }
        }

        public final boolean equals(Object arg3) {
            boolean v0;
            if (this == (((HttpsFilter) arg3))) {
                v0 = true;
            } else {
                if (arg3 != null && this.getClass() == arg3.getClass()) {
                    return this.urlRegex.equals(((HttpsFilter) arg3).urlRegex);
                }

                v0 = false;
            }

            return v0;
        }

        public final int hashCode() {
            return this.urlRegex.hashCode();
        }
    }
}

